package com.xyh.concurrency.example.immutable;

import com.google.common.collect.Maps;
import com.xyh.concurrency.annoations.NotThreadSafe;
import com.xyh.concurrency.annoations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * 不可变对象的创建
 */
@Slf4j
@NotThreadSafe
public class ImmutableExample1 {
    private final static Integer a = 1;
    private final static String b = "2";
    //map 线程不安全 引用对象 内存指定栈的位置可以不变 但是只可以变
    private final static Map<Integer, Integer> map = Maps.newHashMap();

    static {
        map.put(1, 2);
        map.put(3, 4);
        map.put(5, 6);
    }

    public static void main(String[] args) {
        //a = 2;
        //b = "2";
        map.put(1, 3);

    }

    public void test(final int i) {
        //i = 2;
    }

}
